var id,count = 0;//id为场景，count用来判断是否已经选择过至少一次
const Base64 = require('../../utils/data/imgBase64.js');
Page({
  data: {
    selections: [{ id: 1, select:false}, { id: 2, select:false}, { id: 3, select:false},{ id: 4, select:false},{id: 5, select:false}],
    show: 0,
    text: '选择一个场景',
    imgBase64: Base64.imgArray
  },
  onLoad(){
    id = 0,count = 0
  },
  prop: function() {
    if(count != 0 && id == 2){
          wx.navigateTo({url: '../../pages/page2/page2'})//由于页面跳转没有销毁，所以id和count的值不能清零
    }else if(count != 0){
          wx.navigateTo({url: '../../pages/game/game?id='+ id})//传递id到game.js
    }else{
       //提示未选择 
       let that = this;
       this.setData({
             show: 1
       })
       setTimeout(function () {
         that.setData({
           show: 0
         })
       }, 2000)
    }
    },
  selected: function (e) {
    count++;
    id = e.currentTarget.dataset.id;
    id == 2?
      this.setData({
        text: '前去选择道具'
      })
    :
      this.setData({
        select: 1,
        text: '开始游戏'
      })
    
    for (let i = 0; i < this.data.selections.length; i++) {
      if (this.data.selections[i].id == id) {
        //当前点击的位置为true即选中
        this.data.selections[i].select = true;
      }
      else {
        //其他的位置为false
        this.data.selections[i].select = false;
      }
    }
    this.setData({
      selections: this.data.selections,//更新数据，并部署到页面中
    })
  },
})
